#pragma once
#ifndef CLIB_BSD_SOCKET_H
#define CLIB_BSD_SOCKET_H

#include "clib_type.h"
#include "clib_stack_sock.h"

#ifdef __cplusplus
extern "C" {
#endif

int32_t 
clib_bsd_getsockopt(int32_t sockid,
                int32_t level,
                int32_t optname,
                void *optval,
                socklen_t *optlen);

int32_t 
clib_bsd_setsockopt( int32_t sockid,
                     int32_t level,
		               int32_t optname,
                     const void *optval,
                     socklen_t optlen );

int32_t 
clib_bsd_setsock_nonblock(int32_t sockid);

/* mtcp_socket_ioctl: similar to ioctl, 
   but only FIONREAD is supported currently */
int32_t 
clib_bsd_socket_ioctl(int32_t sockid, int32_t request, void *argp);

int32_t 
clib_bsd_socket(int32_t domain, int32_t type, int32_t protocol);

int32_t 
clib_bsd_bind(int32_t sockid, 
		  const struct sockaddr *addr,
          socklen_t addrlen);

int32_t 
clib_bsd_listen(int32_t sockid, int32_t backlog);

int32_t 
clib_bsd_accept(int32_t sockid, struct sockaddr *addr, socklen_t *addrlen);

// int32_t 
// clib_init_rss(mctx_t mctx, in_addr_t saddr_base, int32_t num_addr, 
// 		in_addr_t daddr, in_addr_t dport);

int32_t 
clib_bsd_connect(int32_t sockid, 
		     const struct sockaddr *addr,
             socklen_t addrlen);

int32_t 
clib_bsd_close(int32_t sockid);

int32_t
clib_bsd_getsockname(int32_t sockid,
                 struct sockaddr *addr,
                 socklen_t *addrlen);

int32_t
clib_bsd_getpeername(int32_t sockid,
                 struct sockaddr *addr,
		         socklen_t *addrlen);

inline ssize_t
clib_bsd_read(int32_t sockid, char *buf, size_t len);

// ssize_t
// clib_bsd_recv(int32_t sockid, char *buf, size_t len, int32_t flags);

ssize_t
clib_bsd_write(int32_t sockid, const char *buf, size_t len);

#ifdef __cplusplus
}
#endif

#endif